package com.schuxl.observer.bike.dataobject;

import java.io.Serializable;
import java.util.Calendar;

import org.apache.commons.lang.StringEscapeUtils;

import com.schuxl.observer.bike.util.Util;

public abstract class Ad implements Serializable {
	
	private static final long serialVersionUID = -2899310839780666011L;
	
	protected String bikeName=""; //Title des Bikes aus dem model-filter
	protected Calendar issueDate=null;//Datum an dem die Anzeige zum ersten mal eingelesen wurde (fuer Ablaufdatum)
	protected String priceCalculation=""; //Beschreibung der Preiserhebung fuer Filter



	protected transient String title="";
	protected String link="";
	protected transient String imageLink="";
	protected transient Integer year = null; 
	protected transient String kilometers="";
	protected transient Integer price = null;
	protected transient String dealer="Unbekannt"; //Wird spaeter ueberschrieben (falls bekannt)
	protected transient String location="";
	
	protected transient String seller;
	protected transient String phone;
	protected transient String discription;
	
	protected transient int travelTime = 0;
	protected transient int travelDistance = 0;
	protected transient String travelLink = "";
	protected transient String geoImageLink = "";
	
	



	/**
	 * Liefert die HTML Darstellung dieser Ad
	 * @return HTML-Representation
	 */
	public String getBikeRepresentation() {
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("<h3>").append(title).append(" (").append(bikeName).append(")").append("</h3><br/>");
		if(imageLink!=null && imageLink.length()>0)
			stringBuffer.append("<a href=\"").append(link).append("\">").append("<img width=\"120\" src=\"").append(imageLink).append("\" /></a>").append("<br/><br/>");
		stringBuffer.append("<table>");
		stringBuffer.append("<tr><td>").append("<b>Preis:</b> </td><td>").append(Util.formatPrice(price)).append(",-").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Erstzul.:</b> </td><td>").append(year).append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Standort:</b> </td><td>").append(StringEscapeUtils.escapeHtml(location)).append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Laufl.:</b> </td><td>").append(kilometers).append(" km").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Anbieter:</b> </td><td>").append(StringEscapeUtils.escapeHtml(dealer)).append("</td></tr>");
		stringBuffer.append("<tr><td colspan=\"2\" height=\"10\"></td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Preisberechnung:</b> </td><td>").append(StringEscapeUtils.escapeHtml(priceCalculation)).append("</td></tr>");
		if(travelLink.equals("")==false)
			stringBuffer.append("<tr><td>").append("<b>Von Wien Mitte:</b> </td><td>").append(Util.formatGeoDistance(travelDistance)+", "+Util.formatGeoDuration(travelTime)+", ").append("<a href=\""+travelLink+"\">Route</a>").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Link:</b> </td><td>").append("<a href=\"").append(link).append("\">").append(link).append("</a>").append("</td></tr>");
		stringBuffer.append("</table>");
		
		return stringBuffer.toString();
	}
	
	

	
	public String getBikeName() {
		return bikeName;
	}
	public void setBikeName(String bikeName) {
		this.bikeName = bikeName;
	}
	public Calendar getIssueDate() {
		return issueDate;
	}
	public void setIssueDate(Calendar issueDate) {
		this.issueDate = issueDate;
	}
	public String getPriceCalulation() {
		return priceCalculation;
	}
	public void setPriceCalculation(String priceCalculation) {
		this.priceCalculation = priceCalculation;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getImageLink() {
		return imageLink;
	}
	public void setImageLink(String imageLink) {
		this.imageLink = imageLink;
	}
	public String getKilometers() {
		return kilometers;
	}
	public void setKilometers(String kilometers) {
		this.kilometers = kilometers;
	}
	public Integer getYear() {
		return year;
	}
	public void setYear(Integer year) {
		this.year = year;
	}
	public Integer getPrice() {
		return price;
	}
	public void setPrice(Integer price) {
		this.price = price;
	}
	public String getDealer() {
		return dealer;
	}
	public void setDealer(String dealer) {
		this.dealer = dealer;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getSeller() {
		return seller;
	}
	public void setSeller(String seller) {
		this.seller = seller;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getDiscription() {
		return discription;
	}
	public void setDiscription(String discription) {
		this.discription = discription;
	}
	public int getTravelTime() {
		return travelTime;
	}
	public void setTravelTime(int travelTime) {
		this.travelTime = travelTime;
	}
	public int getTravelDistance() {
		return travelDistance;
	}
	public void setTravelDistance(int travelDistance) {
		this.travelDistance = travelDistance;
	}
	public String getTravelLink() {
		return travelLink;
	}
	public void setTravelLink(String travelLink) {
		this.travelLink = travelLink;
	}
	public String getGeoImageLink() {
		return geoImageLink;
	}
	public void setGeoImageLink(String geoImageLink) {
		this.geoImageLink = geoImageLink;
	}




	@Override
	public String toString() {
		return "Ad [bikeName=" + bikeName + ", issueDate=" + issueDate
				+ ", priceCalculation=" + priceCalculation + ", title=" + title
				+ ", link=" + link + ", imageLink=" + imageLink + ", year="
				+ year + ", kilometers=" + kilometers + ", price=" + price
				+ ", dealer=" + dealer + ", location=" + location + ", seller="
				+ seller + ", phone=" + phone + ", discription=" + discription
				+ ", travelTime=" + travelTime + ", travelDistance="
				+ travelDistance + ", travelLink=" + travelLink
				+ ", geoImageLink=" + geoImageLink + "]";
	}




	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((link == null) ? 0 : link.hashCode());
		return result;
	}
	
												
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ad other = (Ad) obj;
		if (link == null) {
			if (other.link != null)
				return false;
		} else if (!link.equals(other.link))
			return false;
		return true;
	}
	
	
	
	
	
	
	

}
